#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#define _FIFO_FILE_ "fifo"
#define _SRC_FILE_ "src.txt"

int main()
{
    //以w方式打开管道文件
    int wf = open(_FIFO_FILE_, O_WRONLY);
    if(wf < 0)  exit(1);
    //以r方式打开src.txt
    int rs = open(_SRC_FILE_, O_RDONLY);
    if(rs < 0)  exit(2);
    //读取src文件内容，写入到管道文件中
    char buff[1024];
    int n = 0;
    while(n = read(rs,buff,sizeof(buff)-1))//当n等于0时表示读到文件末尾
    {
        //将文件内容写入到管道文件中
        buff[n] = 0;
        write(wf, buff,strlen(buff));
    }
    printf("read src.txt and write fifo success\n");
    return 0;
}